//
//  FortuneDetailView.m
//  SmileWeather
//
//  Created by lanou3g on 15/9/19.
//  Copyright (c) 2015年 陶天海. All rights reserved.
//

#import "FortuneLabelCell.h"
#import "InfoLabelCell.h"

#import "FortuneDetailView.h"

@interface FortuneDetailView()<UITableViewDataSource, UITableViewDelegate>


@end

@implementation FortuneDetailView

- (instancetype)initWithFrame:(CGRect)frame iconModel:(FortuneModel *)model{
    self = [super initWithFrame:frame];
    if (self) {
        //FortuneModel赋值
        [self setLabelAndImage];
        [self.starImage sd_setImageWithURL:[NSURL URLWithString:model.icon]];
        self.titleLabel.text = model.sname;
        self.dateLabel.text = model.cname;
       
        
        self.table = [[UITableView alloc]initWithFrame:CGRectMake(0, self.icon2Image.frame.origin.y + self.icon2Image.bounds.size.height, kWidth, kHeight - self.icon2Image.frame.origin.y - 20) style:UITableViewStyleGrouped];
        [self addSubview:self.table];
        self.table.delegate = self;
        self.table.dataSource= self;
        self.table.backgroundColor = [UIColor clearColor];
        self.table.separatorStyle = UITableViewCellSeparatorStyleNone;
      
        
    }
    return self;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.row == 0) {
        return kHeight / 3.5;
    }else{
        return kHeight / 2.5;
    }
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 2;
}

- (void)setDModel:(FortuneDetailModel *)DModel{
    _DModel = DModel;
    [self.table reloadData];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.row == 0) {
        
        FortuneLabelCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
        if (cell == nil) {
            cell = [[FortuneLabelCell alloc]initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"cell"];
        }
        [cell setModel:self.DModel];
        
        cell.backgroundColor = [UIColor clearColor];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;

        return cell;
    }
    else{
        InfoLabelCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell1"];
        if (cell == nil) {
            cell = [[InfoLabelCell alloc]initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"cell1"];
        }
        cell.backgroundColor = [UIColor clearColor];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        [cell setModel:self.DModel];
        return cell;
    
    
    
    }
}
- (void)setLabelAndImage{
    self.icon1Image = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"hehe.png"]];
    self.icon1Image.frame = CGRectMake(0, 64 , kWidth, 80);
    [self addSubview:self.icon1Image];
    
    self.icon2Image = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"yuncai@3x"]];
    self.icon2Image.frame = CGRectMake(0, self.icon1Image.frame.origin.y + 60, kWidth, 20);
    [self addSubview:self.icon2Image];
    
    
    self.starImage = [[UIImageView alloc] initWithFrame:CGRectMake(kWidth/4, 64, kWidth / 7, self.icon1Image.bounds.size.height - 15)];
    [self addSubview:self.starImage];
    
    self.titleLabel = [[UILabel alloc]initWithFrame:CGRectMake(self.starImage.frame.origin.x + self.starImage.bounds.size.width + 20, self.starImage.frame.origin.y + 20, kWidth / 3, self.starImage.bounds.size.height / 6)];
    [self addSubview:self.titleLabel];
    self.titleLabel.textColor = [UIColor whiteColor];
    
    self.dateLabel = [[UILabel alloc]initWithFrame:CGRectMake(self.titleLabel.frame.origin.x, self.titleLabel.frame.origin.y + self.titleLabel.bounds.size.height, kWidth / 3, self.starImage.bounds.size.height / 2)];
    [self addSubview:self.dateLabel];
    self.dateLabel.textColor = [UIColor whiteColor];
    self.dateLabel.font = [UIFont systemFontOfSize:14];
    
}

@end
